package com.jprocms.module.cms.dal.mysql.operate;

import com.jpro.framework.mybatis.core.mapper.BaseMapperX;
import com.jpro.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.jprocms.module.cms.controller.portal.vo.OperateQueryReqVO;
import com.jprocms.module.cms.dal.dataobject.operate.OperateDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 操作记录 Mapper
 *
 * @author JPROCMS
 */
@Mapper
public interface OperateMapper extends BaseMapperX<OperateDO> {

    default List<OperateDO> selectList(OperateQueryReqVO reqVO) {
        LambdaQueryWrapperX<OperateDO> queryWrapperX = new LambdaQueryWrapperX<OperateDO>()
                .eqIfPresent(OperateDO::getOpeType, reqVO.getOpeType())
                .eqIfPresent(OperateDO::getOpeDataId, reqVO.getOpeDataId())
                .eqIfPresent(OperateDO::getIp, reqVO.getIp())
                .eqIfPresent(OperateDO::getUserId, reqVO.getUserId())
                .eqIfPresent(OperateDO::getIdentityCookie, reqVO.getIdentityCookie())
                .gtIfPresent(OperateDO::getCreateTime, reqVO.getDate())
                .orderByDesc(OperateDO::getId);
        return selectList(queryWrapperX);
    }

    default Long selectCount(OperateQueryReqVO reqVO) {
        LambdaQueryWrapperX<OperateDO> queryWrapperX = new LambdaQueryWrapperX<OperateDO>()
                .eqIfPresent(OperateDO::getOpeType, reqVO.getOpeType())
                .eqIfPresent(OperateDO::getOpeDataId, reqVO.getOpeDataId())
                .eqIfPresent(OperateDO::getIp, reqVO.getIp())
                .eqIfPresent(OperateDO::getUserId, reqVO.getUserId())
                .eqIfPresent(OperateDO::getIdentityCookie, reqVO.getIdentityCookie())
                .gtIfPresent(OperateDO::getCreateTime, reqVO.getDate())
                .orderByDesc(OperateDO::getId);
        return selectCount(queryWrapperX);
    }

}
